<?php
/**
 * Created by PhpStorm.
 * User: zyark
 * Date: 2017/5/27
 * Time: 15:36
 */

namespace Home\Logic;


class GoodsCategoryLogic
{
    /**
     * 获取顶级商品分类列表 三级
     */
   public function getTopCategoryList(){
       $topCategoryList = D('GoodsCategory')->where(array('parent_id'=>'0','is_show'=>1))->Order('sort_order desc')->select();
       foreach ($topCategoryList as $key => $value){
           $parentId = $topCategoryList[$key]['id'];
           $categoryList = D('GoodsCategory')->where(array('parent_id'=>$parentId,'is_show'=>1))->select();
           foreach ($categoryList as $k => $v){
               $twoParentId = $categoryList[$k]['id'];
               $downCategoryList = D('GoodsCategory')->where(array('parent_id'=>$twoParentId,'is_show'=>1))->select();

               foreach ($downCategoryList as $ke => $val){

                   if(!M('Goods')->where(array('cat_id'=>$val['id'], 'is_on_sale'=>1))->count())
                        unset($downCategoryList[$ke]);
               }


               $categoryList[$k]['categoryList'] = $downCategoryList;
           }
           $topCategoryList[$key]['categoryList'] = $categoryList;
       }
       return $topCategoryList;
   }

}